import { createStore, Store, useStore as baseUseStore } from 'vuex'
import { IRootState, IStoreType } from './types'
import { localCache } from '@/cache'
import loginModule from './login/login'
const store = createStore<IRootState>({
  state: () => {
    return {
      language: localCache.getItem('lang') || 'zh-cn'
    }
  },
  mutations: {
    setLanguage(state, lang) {
      localCache.setItem('lang', lang)
      state.language = lang
    }
  },
  modules: {
    login: loginModule
  }
})
export function setUpStore() {
  store.dispatch('login/loadLocalLogin')
}
export function useStore(): Store<IStoreType> {
  return baseUseStore()
}
export default store
